<?php
include("../contents.php");
include("../security.php");
include("../settings.php");
include("../database.php");
include("../navigation.php");

if (!empty($_POST)) {
	//	print_r($_POST);
	if (!empty($_POST["url"]) && !empty($_POST["type"]) && !empty($_GET["fenster"])) {
		$insertedlink=Contents::create_content_link($_POST["type"], $_POST["url"], $_POST["target"]);
		if ($insertedlink!=null) {
    			?>
    			<script type="text/javascript" language="JavaScript">
    			<!--
    			opener.selectURL("<?php echo $_GET["fenster"]; ?>","link://<?php echo $insertedlink; ?>");
    			self.close();
    			// -->
    			</script>
    			<?php
		} else {
			die("Leider ist beim Einfuegen ein Fehler aufgetreten.");
		}
	}
}
echo "<"."?xml version=\"1.0\"?".">";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Administration</title>
    <link media="screen" rel="stylesheet" href="css/style.css" type="text/css" />
    <script src="js/scripts.js" type="text/javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    function submitForm(type, url) {
    	document.forms[0].elements["url"].value=url;
    	document.forms[0].elements["type"].value=type;
    	document.forms[0].submit();
    }
    // -->
    </script>
    </head>

    <body id="edit">
    <?php
    $GLOBALS["linkzusatz"]="";
    if (!empty($_GET["fenster"])) {
    	$GLOBALS["linkzusatz"].="&fenster=". $_GET["fenster"];
    }
    ?>
    <form id="linkform" action="<?php echo $_SERVER["PHP_SELF"]; ?>?<?php echo $GLOBALS["linkzusatz"]; ?>" method="post">
    <input type="hidden" name="url" value=""/>
    <input type="hidden" name="type" value=""/>
    <p id="pageheadline">W&auml;hlen Sie einen Zielframe:</p>
    <select size="1" name="target">
    	<option value="">Kein spezieller Frame</option>
    	<option value="_blank">Neues Fenster</option>
    	<option value="_self">Selber Frame</option>
    	<option value="_parent">&uuml;bergeordneter Frame</option>
    </select>
    <p id="pageheadline">Externer Link:</p>
    	<input type="text" value="http://" name="extlink" size="40" />
    	<input type="button" value="Einf&uuml;gen" onclick="submitForm('2', document.forms[0].elements['extlink'].value);"/>
  	<p id="pageheadline">W&auml;hlen Sie eine Seite:</p>
   	<?php
   	list_contents($_GET["pres"]);
   	echo "<br />";
   	?>
  	<p id="pageheadline">W&auml;hlen Sie einen Navigationspunkt:</p>
   	<?php
   	list_navigations($_GET["pres"]);
   	echo "<br />";
   	?>
  	<p id="pageheadline">W&auml;hlen Sie eine Datei:</p>
   	<?php
   	list_media($_GET["pres"], 0, 1);
   	echo "<br />";
    ?>
   	</form>
    </body>
    </html>